<?php
/*------------------------------------------------------------------------
 # SM Mega Menu - Version 1.1
 # Copyright (c) 2013 YouTech Company. All Rights Reserved.
 # @license - Copyrighted Commercial Software
 # Author: YouTech Company
 # Websites: http://www.magentech.com
-------------------------------------------------------------------------*/
include_once 'Mobile_Detect.php';
$prefix = Sm_Megamenu_Model_System_Config_Source_Html::PREFIX;
$smarthelper= Mage::helper('megamenu/utils');
$itemsStartLv = $this->getItems();
$config = $this->getConfigObject();
$uq = uniqid($prefix.'menu');
$detect = new Mobile_Detect();
if($config['theme']==Sm_Megamenu_Model_System_Config_Source_ListTheme::HORIZONTAL){
$theme = 'horizontal';
}
if($config['theme']==Sm_Megamenu_Model_System_Config_Source_ListTheme::VERTICAL){
$theme = 'vertical'; 
}
$instance	= rand().time();
//echo $this->getScriptTags();
?>
<?php if(count($itemsStartLv)):?>
	<?php include dirname(__FILE__) . '/js/add_js_by_effect.phtml'; ?>
	<?php include dirname(__FILE__) . '/css/add_css_by_theme.phtml'; ?>

	<?php if (!empty($config['title'])): ?>
	<div class="<?php echo $prefix; ?>block-title" style="font-size: 16px; font-weight: bold;"><?php echo $config['title']; ?></div>
	<?php endif; ?>
	
	<div class="<?php echo $prefix; ?>wrapper_<?php echo $theme?>_menu sambar" id="<?php echo $uq; ?>" data-sam="<?php echo $instance; ?>">
		<div class="sambar-inner">
			<a class="btn-sambar" data-sapi="collapse" href="<?php echo '#'.$uq; ?>">
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
			</a>	
			<ul class="<?php if ( !$detect->isMobile() && !$detect->isTablet() ) { echo "sm-megamenu-hover";}?> <?php echo $prefix; ?>menu <?php echo $prefix; ?>menu_black" data-jsapi="on">
			<?php 	foreach($itemsStartLv as $itemStartLv){		?>
						<li class="<?php if($itemStartLv->getCustomClass()){ echo $itemStartLv->getCustomClass().'-parent ';}?> <?php if( $config['effect'] == 1 || $config['effect'] == 2 ){ echo 'other-toggle ';}?>  
						<?php echo $prefix; ?>lv1 <?php echo (!$this->isLeaf($itemStartLv) OR ($this->isLeaf($itemStartLv) AND $this->hasConntentType($itemStartLv)))?$prefix.'drop parent':$prefix.'nodrop'?>  <?php echo ($this->isAlignRight($itemStartLv))?$prefix.'right':''?> <?php echo ($this->isActived($itemStartLv))?$prefix.'actived':'' ?>">
												<a class="<?php echo $prefix; ?>head <?php echo (!$this->isLeaf($itemStartLv) OR ($this->isLeaf($itemStartLv) AND $this->hasConntentType($itemStartLv)))?$prefix.'drop':$prefix.'nodrop'?> <?php echo ($this->isActived($itemStartLv))?$prefix.'actived'.' '.$prefix.'top_actived':'' ?>" href="<?php echo ($this->hasLinkType($itemStartLv))?$this->getLinkOfType($itemStartLv):'javascript:void(0)'?>" <?php echo ($this->hasLinkType($itemStartLv))?$smarthelper->getTargetAttr($itemStartLv->getTarget()):'' ?> id="<?php echo $prefix.$itemStartLv->getId()?>">
													<?php if($this->hasIcon($itemStartLv)) {	?>
													<span class="<?php echo $prefix; ?>icon <?php if(!$itemStartLv->getDescription()){echo $prefix.'nodesc';}?>">		
													<?php }else{	?>
													<span class="<?php echo $prefix; ?>icon <?php if(!$itemStartLv->getDescription()){echo $prefix.'nodesc';}?>">		
													<?php } ?>
															<span class="<?php echo $prefix; ?>title"><?php echo $itemStartLv->getTitle() ?></span>
														<?php if($itemStartLv->getDescription()):?>
															<span class="<?php echo $prefix; ?>description"><?php echo $itemStartLv->getDescription() ?>&nbsp;</span>	
														<?php endif?>			
													<?php //if($this->hasIcon($itemStartLv)) {	?>	
													</span>
													<?php //}	?>
													<?php if($this->hasIcon($itemStartLv)) {	?>
													<span class="icon-item-menu"><img src="<?php echo $this->filterImage($itemStartLv);?>" /></span>
													<?php } ?>
												</a>
						<?php $childItems = Mage::helper('megamenu')->getChildsDirectlyByItem($itemStartLv);?>
						<?php 	if($this->isLeaf($itemStartLv) OR !count($childItems->getItems())){ 	?>
									<?php 	if($this->hasConntentType($itemStartLv)){	?>
												<div class="<?php echo $prefix; ?>dropdown_<?php echo $itemStartLv->getColsNb()?><?php if($itemStartLv->getColsNb()>1){ ?>columns<?php }else{ ?>column<?php } ?> <?php echo ($this->isAlignRight($itemStartLv))?$prefix.'align_right':''?> 
												<?php echo ($this->isActived($itemStartLv))?$prefix.'actived':'' ?>" >
													<?php if($itemStartLv->getShowTitle()==Sm_Megamenu_Model_System_Config_Source_Status::STATUS_ENABLED){	?>
													<div class="<?php echo $prefix; ?>title"><span><?php echo $itemStartLv->getTitle()?></span></div>
													<?php } ?>
													<div class="<?php echo $prefix; ?>content"><?php echo $this->getContentType($itemStartLv) ?></div>
												</div>
									<?php 	}	?>
						<?php 		continue;	
								}	?>
							<?php 
							if($itemStartLv->getColsNb()>1){ 
								$divClassName = 'sm-megamenu-child ' .$prefix.'dropdown_'.$itemStartLv->getColsNb().'columns ';
							}
							else{
								$divClassName = $prefix.'dropdown_'.$itemStartLv->getColsNb().'column ';
							}
								if($this->isAlignRight($itemStartLv)){
									$divClassName .= $prefix.'align_right';
								}
								/*if($this->isFlyLeft($itemStartLv)){
									$divClassName .= " ".$prefix.'fly_left_wrap';
								}*/							
							?>
						<?php 	if($itemStartLv->getDepth()+1 <= $config['end_level']){ ?>
												<div class="<?php echo $divClassName?>">	
													<?php echo $this->getItemHtml($itemStartLv, true);	 ?>
												</div>
						<?php 	} ?>
						</li>
			<?php	}	?>
			</ul>
		</div>
	</div>
	<!--End Module-->
<?php else: ?>
<p class="note-msg"><?php echo $this->__('There are no items matching the selection.') ?></p>
<?php endif; ?>


<script type="text/javascript">
// <![CDATA[ 
$jsmart(document).ready(function(){
	$jsmart('.sm_megamenu_wrapper_vertical_menu .sm_megamenu_menu > li').has('ul').addClass('parent-item');

	var menu_width = $jsmart('.sm_megamenu_wrapper_horizontal_menu').width();
	$jsmart('.sm_megamenu_wrapper_horizontal_menu .sm_megamenu_menu > li > div').each(function(){
		$this = $jsmart(this);   
		var lv2w = $this.width();
		var lv2ps = $this.position();
		var lv2psl = $this.position().left;
		var sw = lv2w + lv2psl;
		if( sw > menu_width ){
			$this.css({'right': '0'});
		}   
	});
});
// ]]> 
</script>
<script type="text/javascript">
	/* $jsmart('document').ready(function($){
		$i = 0;
		$('.sm_megamenu_wrapper_vertical_menu ul.sm_megamenu_menu').append('<div class="more-w"><span class="more-view">More Categories</span></div>');
		$('.sm_megamenu_wrapper_vertical_menu ul.sm_megamenu_menu > li').each(function(){
			$i ++;
			if($i>8){
				$(this).css('display', 'none');
			}
			
		});
		$('.sm_megamenu_wrapper_vertical_menu ul.sm_megamenu_menu .more-w > .more-view').click(function(){
			if($(this).hasClass('open')){
				$i=0;
				$('.sm_megamenu_wrapper_vertical_menu ul.sm_megamenu_menu > li').each(function(){
					$i ++;
					if($i>8){
						$(this).slideUp(200);
					}
				});
				$(this).removeClass('open');
				$('.more-w').removeClass('active-i');
				$(this).text('More Categories');
			}else{
				$i=0;
				$('.sm_megamenu_wrapper_vertical_menu ul.sm_megamenu_menu > li').each(function(){
					$i ++;
					if($i>8){
						$(this).slideDown(200);
					}
				});
				$(this).addClass('open');
				$('.more-w').addClass('active-i');
				$(this).text('Close Menu');
			}
		});
	}) */
</script>